package com.hadoop.mr.amiudake.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WorldCountDriver {
	public static String NAME_NODE_URL = "hdfs://192.168.186.6:9000";
	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		Job job = Job.getInstance(conf);
		
		job.setJarByClass(WorldCountDriver.class);//设置运行主类
		job.setMapperClass(WordCountMapper.class);
		job.setReducerClass(WordCountReduce.class);
		
		//设置mapper 输出key类型
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(LongWritable.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(LongWritable.class);
		
		//指定文件的HDFS读取路径
		FileInputFormat.setInputPaths(job, new Path(NAME_NODE_URL + "/mr/words.txt"));
		//指定输出结果文件目录，指定的目录不能存在
		FileOutputFormat.setOutputPath(job, new Path(NAME_NODE_URL + "/mr/words/result"));
		
		//启动组件
		job.waitForCompletion(true);
	}
}
